﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.Business;

namespace QuanLyThuVien.Presentation
{
    public partial class frmThongTinNXB : Form
    {
        public frmThongTinNXB()
        {
            InitializeComponent();
        }
        NXBBUS nxb = new NXBBUS();
        NXB NXB = new NXB();
        private void frmThongTinNXB_Load(object sender, EventArgs e)
        {
            nxb.LoadLenDataGV(dgThongTinTG);
        }

        private void btnNhapNXB_Click(object sender, EventArgs e)
        {
            try
            {
                NXB.MaNXB = txtMaNXB.Text;
                NXB.TenNXB = txtTenNXB.Text;
                NXB.DiaChi = txtDiaChi.Text;
                NXB.DienThoai = txtSDT.Text;
                nxb.ThemMoiNXB(NXB);
                nxb.LoadLenDataGV(dgThongTinTG);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "QuanLyThuVien");
            }
        }

        private void btnTaoMoiNXB_Click(object sender, EventArgs e)
        {
            txtMaNXB.Text = "";
            txtTenNXB.Text = "";
            txtDiaChi.Text = "";
            txtSDT.Text = "";
        }

        private void btnSuaNXB_Click(object sender, EventArgs e)
        {

            if (MessageBox.Show("Bạn có thực sự muốn sửa thông tin NXB hay không?", "QuanLyThuVien", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                NXB.MaNXB = txtMaNXB.Text;
                NXB.TenNXB = txtTenNXB.Text;
                NXB.DiaChi = txtDiaChi.Text;
                NXB.DienThoai = txtSDT.Text;
                nxb.SuaNXB(NXB);
                nxb.LoadLenDataGV(dgThongTinTG);
            }
        }

        private void btnXoaNXB_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có thực sự muốn xóa thông tin NXB hay không?", "QuanLyThuVien", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                nxb.XoaNXB(txtMaNXB.Text);
                nxb.LoadLenDataGV(dgThongTinTG);
            }
        }

        private void dgThongTinTG_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int a = e.RowIndex;
            txtMaNXB.Text=dgThongTinTG[0,a].Value.ToString();
            txtTenNXB.Text=dgThongTinTG[1,a].Value.ToString();
            txtDiaChi.Text = dgThongTinTG[2, a].Value.ToString();
            txtSDT.Text = dgThongTinTG[3, a].Value.ToString();
        }
    }
}
